package com.android.kotlincoroutinemvvmdemo.adapter
import android.content.Context
import com.android.kotlincoroutinemvvmdemo.R
import com.android.kotlincoroutinemvvmdemo.bean.OneFi
import com.android.kotlincoroutinemvvmdemo.databinding.RvDaynightItemLayoutBinding
import com.android.kotlincoroutinemvvmdemo.event.DayNightEvent

class DayNightModeAdapter(context: Context) : BaseRVAdapter<RvDaynightItemLayoutBinding, OneFi>() {

    private val mContext = context

    override fun getLayoutId() = R.layout.rv_daynight_item_layout

    override fun bindData(
        holder: RVViewHolder<RvDaynightItemLayoutBinding>,
        dataItem: OneFi,
        position: Int
    ) {
        dataItem.itemPosition = position
        holder.mBinding.oneFi = dataItem
        holder.mBinding.itemEvent = DayNightEvent(mContext, this)
    }

    override fun adapterUIModeNightForRecyclerView(uiModeNight: Boolean) {
        super.adapterUIModeNightForRecyclerView(uiModeNight)
        for (mBindingItem in mBindingList) {
            adapterUIModeNightForRecyclerView(mBindingItem, uiModeNight)
        }
    }

    override fun adapterUIModeNightForRecyclerView(
        mBinding: RvDaynightItemLayoutBinding,
        uiModeNight: Boolean
    ) {
        super.adapterUIModeNightForRecyclerView(mBinding, uiModeNight)
        if (uiModeNight) {
            mBinding.rvDayNightModeItemRoot.background = mContext.resources.getDrawable(R.drawable.layout_bg_07)
        } else {
            mBinding.rvDayNightModeItemRoot.background = mContext.resources.getDrawable(R.drawable.layout_bg_06)
        }
    }
}